import {createContext} from "react";
import Welcome from "./components/welcome";
import Userinfo from "./components/userinfo";
import School from "./components/info/school";
import Classroom from "./components/info/classroom";
import Teacher from "./components/info/teacher";
import Course from "./components/info/course";
import Student from "./components/school/student";
import Order from "./components/finance/order";
import ClassGroup from "./components/school/class-group";
import LessonSchedule from "./components/lesson/lesson-schedule";
import LessonScheduleConfig from "./components/lesson/lesson-schedule-config";
import LessonConfirmed from "./components/lesson/lesson-confirmed";
import LessonHistory from "./components/lesson/lesson-history";
import ScheduleList from "./components/lesson/schedule-list";
import Referrer from "./components/finance/referrer";
import Commission from "./components/finance/commission";

export const lessonComplete = {
    key: "lesson-complete",
    role: ["TEACHER"],
    name: "销课",
    icon: "task_alt",
    component: <LessonConfirmed/>
};

export const manualSchedule = {
    key: "manual-schedule",
    name: "课程编排",
    icon: "app_registration",
    component: <LessonSchedule/>
};

const principal = [
    {
        key: "info",
        name: "资料管理",
        icon: "description",
        children: [
            {key: "school-info", name: "学校信息", icon: "announcement", component: <School/>},
            {key: "classroom-info", name: "教室信息", icon: "new_releases", component: <Classroom/>},
            {key: "teacher-info", name: "教师信息", icon: "account_circle", component: <Teacher/>},
            {key: "course-info", name: "课程信息", icon: "library_books", component: <Course/>}
        ]
    },
    {
        key: "school",
        name: "学校管理",
        icon: "school",
        children: [
            {key: "student", name: "学生管理", icon: "person", component: <Student/>},
            {key: "class", name: "班级管理", icon: "group", component: <ClassGroup/>},
        ]
    },
    {
        key: "course",
        name: "课程管理",
        icon: "access_time",
        children: [
            {key: "lesson-schedule-config", name: "编排配置", icon: "tune", component: <LessonScheduleConfig/>},
            // 课程编排
            manualSchedule,
            {
                key: "schedule-list",
                role: ["TEACHER", "PARENT", "STUDENT"],
                name: "课程表",
                icon: "calendar_month",
                component: <ScheduleList/>
            },
            // 销课
            lessonComplete,
            {key: "lesson-history", name: "授课历史", icon: "format_list_bulleted", component: <LessonHistory/>},
        ]
    },
    {
        key: "finance",
        name: "财务管理",
        icon: "account_balance",
        children: [
            {key: "order", name: "订单管理", icon: "shopping_cart", component: <Order/>},
            {key: "referrer-manage", name: "推广管理", icon: "record_voice_over", component: <Referrer/>},
            {key: "commission", name: "佣金管理", icon: "money", component: <Commission/>}
        ]
    }
]

export const welcome = {
    key: "welcome",
    name: "欢迎",
    component: <Welcome/>,
    cache: true
}

export const userinfo = {
    key: "userinfo",
    name: "用户信息",
    component: <Userinfo/>
}

export const getMenu = (role) => {
    return role === "PRINCIPAL" ? principal :
        principal
            .map(m => ({...m, children: m.children.filter(sm => sm.role?.includes(role))}))
            .filter(m => m.children?.length);
}

export const MyContext = createContext({
    handleMenuClick: () => void 0,
});
